package com.woniu.controller.frontUser;

import com.woniu.controller.BaseController;
import com.woniu.entity.Result;
import com.woniu.pojo.*;
import com.woniu.pojo.Package;
import com.woniu.service.IFrontUserService;
import com.woniu.service.IOrganizationService;
import com.woniu.vo.ServiceSubmitVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/frontUser")
@Api(tags = "前台用户居民")
public class FrontUserController extends BaseController {
    @Resource
    private  IOrganizationService organizationService;
    @Resource
    private IFrontUserService frontUserService;

    /**
     * 查询所有机构
     * @return
     */
    @GetMapping("/orginazation")
    @ApiOperation("查询所有机构")
    public Result getAllOrganization(){
        List<Organization> organizationList = organizationService.list();
        return toDataResult(organizationList);
    }

    /**
     * 根据机构id查询所有团队团队
     * @return
     */
    @GetMapping("/team/{organizationId}")
    @ApiOperation("根据机构id查询所有团队团队")
    public Result getAllTeamByOrganizationId(@PathVariable Long organizationId){
      List<Team> teamList= frontUserService.getAllTeamByOrganizationId(organizationId);
      return toDataResult(teamList);
    }
    /**
     * 根据机构id查询所有服务包
     */
    @GetMapping("/package/{organizationId}")
    @ApiOperation("根据机构id查询所有服务包")
    public Result getAllPackageByOrganizationId(@PathVariable Long organizationId){
        List<Package> packageList= frontUserService.getAllPackageByOrganizationId(organizationId);
        return toDataResult(packageList);
    }
    /**
     * 根据团队id查询所有服务包
     */
    @GetMapping("/package/{teamId}")
    @ApiOperation("根据团队id查询所有医生")
    public Result getAllDoctorByTeamId(@PathVariable Long teamId){
        List<Doctor> doctorList= frontUserService.getAllDoctorByTeamId(teamId);
        return toDataResult(doctorList);
    }

    /**
     * 签约
     */
    @PostMapping("/doSign")
    @ApiOperation("提交申请签约")
    public Result doSign(@RequestBody Sign sign){
      Boolean flag=  frontUserService.doSign(sign);
      return toResult(flag);
    }
    /**
     * 根据签约id查询签约的订单
     */
    @GetMapping("/sign/{signId}")
    @ApiOperation("根据签约id查询签约的订单")
    public Result querySignById(@PathVariable Long signId){
       Sign sign= frontUserService.querySignById(signId);
       return toDataResult(sign);
    }

    /**
     * 支付
     */
    @PutMapping("/doPay")
    @ApiOperation("支付")
    public Result doPay(@RequestBody Sign sign){
        Boolean flag=  frontUserService.doPay(sign);
        return toResult(flag);
    }

    /**
     * 申请服务（创建）
     */
    @PostMapping("/applyService")
    @ApiOperation("申请服务（创建）")
    public Result applyService(@RequestBody ServiceSubmitVo serviceSubmitVo){
     Boolean flag= frontUserService.applyService(serviceSubmitVo);
     return toResult(flag);
    }
}
